package com.qbw.app.module.common.holder;

import android.content.Context;
import androidx.databinding.ViewDataBinding;
import android.view.View;
import android.view.ViewGroup;

import com.http.okhttp.HttpTask;
import com.qbw.app.manager.GeneralManager;
import com.qbw.core.base.BaseActivity;
import com.qbw.core.base.BaseHolder;

/**
 * @author QBW
 * @date 2019/8/29
 */
public abstract class CommonHolder<T, B extends ViewDataBinding> extends BaseHolder<T, B> implements HttpTask.CallBack {

    protected GeneralManager mGeneralManager = GeneralManager.getInstance();

    public CommonHolder(Context context, View itemView) {
        super(context, itemView);
    }

    public CommonHolder(Context context, ViewDataBinding binding) {
        super(context, binding);
    }

    public CommonHolder(Context context, int layoutResId, ViewGroup viewParent) {
        super(context, layoutResId, viewParent);
    }

    public CommonHolder(Context context, int layoutResId, ViewGroup viewParent, Object listener) {
        super(context, layoutResId, viewParent, listener);
    }

    protected View.OnClickListener mClickListenerItem = v -> {
        onClickItem();
    };

    protected void onClickItem() {

    }

    @Override
    public void onHttpStart(HttpTask httpTask) {

    }

    @Override
    public void onHttpSuccess(HttpTask httpTask, Object entity) {

    }

    @Override
    public void onHttpFailed(HttpTask httpTask, int errorCode, String message) {

    }

    protected void showLoading(String text) {
        if (mContext instanceof BaseActivity) {
            ((BaseActivity) mContext).showLoadingDialog(text);
        }
    }

    protected void closeLoading() {
        if (mContext instanceof BaseActivity) {
            ((BaseActivity) mContext).closeLoadingDialog();
        }
    }
}
